﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using ThongTin;
using DuLieu;
using ThaoTac;

namespace GiaoDien
{
    public partial class frmDanhSachKhoaHoc : Form
    {
        KhoaHoc_DL kh = new KhoaHoc_DL();
        public frmDanhSachKhoaHoc()
        {
            InitializeComponent();
            tblSanhSachKhoaHoc.DataSource = kh.DanhSachKhoaHoc();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            // thêm khóa học
            frmQuanLyKhoaHoc tt = new frmQuanLyKhoaHoc();
            tt.addNew += new EventHandler(add);
            tt.Show();
        }
        public void add(Object sender, EventArgs e)
        {
            frmQuanLyKhoaHoc tt = (frmQuanLyKhoaHoc)sender;
            DataTable dt = (DataTable)tblSanhSachKhoaHoc.DataSource;
            dt.Rows.Add(tt.MaKhoaHoc, tt.NgayBatDau, tt.NgayKetThuc);
            tblSanhSachKhoaHoc.DataSource = dt;

            //day xuong 
            SqlConnection cnn = KetNoi_DL.ketnoi();
            SqlCommand cmd = new SqlCommand("ThemKhoaHoc", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            SqlCommandBuilder cmb = new SqlCommandBuilder(da);
            da.UpdateCommand = cmb.GetUpdateCommand();
            da.Update(dt);
        }
    }
}
